var groupMd = {
    template: '#groupMd',
    methods: {
        onRefresh(done) {
            this.noMore = false
            if (this.mdDbHelper == null) {
                this.mdDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
                this.mdDbHelper.equalTo('groupId',this.groupId)
                
            }
            this.mdDbHelper.current = 1;
            this.mdDbHelper.page = 20;
            that = this;
            loadMd(this.mdDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
                done()
            })

        },

        onInfinite(done) {
            if (this.noMore) {
                done()
                return
            }
            if (this.mdDbHelper == null) {
                this.mdDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
                this.mdDbHelper.equalTo('groupId',this.groupId)
                this.mdDbHelper.page = 20;
                this.mdDbHelper.current = 1;
            }
            this.mdDbHelper.current += 1;

            that = this;
            loadMd(this.mdDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items.concat(arg)
                    that.noMore = true
                } else {
                    that.items.concat(arg)
                }
                done()
            })
        },
        onSearch(data) {

        },
        clean(){
            mapCatch.set('#groupMd', {
            })
        },
      
        onItemClick(index) {
            eventBus.isback=false
			mapCatch.set('mdViewerData',this.items[index])
            $router.push('/main/mdViewer')
        },
        setCatch(){
            mapCatch.set('#groupMd', {
                keywords: this.keywords,
                items: this.items,
                noMore: this.noMore,
                mdDbHelper: this.mdDbHelper,
                groupId:this.groupId,
                groupName:this.groupName
            })
        }
    },
    data() {
        return {        
            keywords: '',
            items: [],
            groupName:'访客组',
            groupId:'',
            noMore: false,
            mdDbHelper: null,
        }
    },
    beforeDestroy() {
        if(!eventBus.isback){
            this.setCatch()
        }else{
            this.clean()
        }
    },
    mounted() {

        let cacth = mapCatch.get('#groupMd')
        if (cacth &&cacth.groupId &&cacth.items.length > 0) {
            this.keywords = cacth.keywords;
            this.items = cacth.items;
            this.noMore = cacth.noMore;
            this.mdDbHelper = cacth.mdDbHelper;
            this.groupId= cacth.groupId;
            this.groupName= cacth.groupName;
            eventBus.isback=true
            return
        }
        if(this.$route.params.groupId)
        this.groupId=this.$route.params.groupId
        if(this.$route.params.groupName)
        this.groupName=this.$route.params.groupName
        if (this.items.length > 0) {
            return
        }
        
        this.groupId=this.$route.params.groupId
        this.groupName=this.$route.params.groupName
        
        if (this.mdDbHelper == null) {
            this.mdDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
            this.mdDbHelper.equalTo('groupId',this.groupId)
            this.mdDbHelper.current = 1;
            this.mdDbHelper.page = 20;
            that = this;
            loadMd(this.mdDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
            })
        }
    },
}